﻿#region Using Declarations

using System.Data.Entity;
using SocialFront.Core.Persistence;

#endregion

namespace SocialFront.Core.Initializers
{
    public class EntityFrameworkBootStrapper
    {
        private static void setInitializer()
        {
            Database.SetInitializer(new StoreFrontContextIntializer());
        }

        private static void setUniqueConstraints()
        {
            // EXAMPLE ONLY. 
            // SocialFrontDataContextFactory.GetDataContext().Database.ExecuteSqlCommand("ALTER TABLE BLAH ADD CONSTRAINT uc_UserName UNIQUE(UserName)");
        }

        public static void CreateAndInitializeDatabase()
        {
            setInitializer();
            setUniqueConstraints();
            SocialFrontDataContextFactory.GetDataContext().SaveChanges();

            // The reason we remove the context here is because ExecuteSqlCommand 
            // disposes the underlying ObjectContext.
            SocialFrontDataContextFactory.RemoveDataContext();
        }
    }
}
